from django.db import models
from django.contrib.auth.models import AbstractUser

# Create your models here.

class UserModel(AbstractUser):
    CHOICES = (
        ('0', '管理员'),
        ('1', '普通用户'),
        ('2', '医生'),
    )
    role = models.CharField(max_length=10, choices=CHOICES, default='user', verbose_name='用户角色')
    avatar = models.ImageField(upload_to='avatar/%Y/', null=True, verbose_name='个人头像')
    username = models.CharField(max_length=50,default="", unique=True, null=True, verbose_name='用户昵称')
    phone = models.CharField(max_length=20, blank=True, verbose_name='手机号')
    email = models.CharField(max_length=20, blank=True, verbose_name='邮箱')
    password = models.CharField(max_length=100, verbose_name='密码')

    # sms_code = models.CharField(max_length=6, blank=True, verbose_name='验证码')

    # money = models.DecimalField(max_digits=9, decimal_places=2, default=0.0, verbose_name='钱包余额')
    # credit = models.IntegerField(default=0, verbose_name='积分')

    def __str__(self):
        return self.username

    class Meta:
        db_table = 'user'
        verbose_name_plural = '用户信息'


# 三方登录表
class ThirdPartyAuth(models.Model):
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name='用户')
    type = models.CharField(max_length=50, unique=True, verbose_name='类型')
    uid = models.CharField(max_length=255, verbose_name='三方平台用户ID')

    def __str__(self):
        return f"{self.type} - {self.uid}"

    class Meta:
        db_table = 'ThirdPartyAuth'
        verbose_name_plural = '三方登录'
